﻿using System.Web.Security;

namespace netaddICTs.Umb.ProtectedMedia.Business.Encryption{
    
    public class Library{
    
        private readonly Configuration.ProtectedMedia _cfg = Configuration.ProtectedMedia.Instance;

        public string GenerateSHA1(int mediaId){
            var inputForSHA1 = string.Format("{0}{1}", mediaId, _cfg.SHA1);

            return FormsAuthentication.HashPasswordForStoringInConfigFile(inputForSHA1, "SHA1");
        }

        public bool IsSHA1Ok(string mediaId, string sha1){
            var inputForSHA1 = string.Format("{0}{1}", mediaId, _cfg.SHA1);
            var sha1Output = FormsAuthentication.HashPasswordForStoringInConfigFile(inputForSHA1, "SHA1");

            return (string.Compare(sha1, sha1Output, false) == 0);
        }

        public string GenerateInternalDownloadSHA1(int mediaId){
            var inputForSHA1 = string.Format("{0}{1}", mediaId, _cfg.InternalDownloadSHA1);

            return FormsAuthentication.HashPasswordForStoringInConfigFile(inputForSHA1, "SHA1");
        }

        public bool IsInternalDownloadSHA1Ok(string mediaId, string sha1){
            var inputForSHA1 = string.Format("{0}{1}", mediaId, _cfg.InternalDownloadSHA1);
            var sha1Output = FormsAuthentication.HashPasswordForStoringInConfigFile(inputForSHA1, "SHA1");

            return (string.Compare(sha1, sha1Output, false) == 0);
        }
    }
}